package controllers.operator;

import hprose.HproseClinetService;

import java.util.HashMap;
import java.util.Map;

import utils.convert.Convert;
import utils.logs.LogsUtils;

import com.alibaba.fastjson.JSONObject;

import component.UserBis;
import constants.APIConstants;
import constants.Constants;
import controllers.common.filter.BaseFilter;

public class OperatorManageAction extends BaseFilter{
	
	
	public static void index(){
		render();
	}
	
	public static void getOperatorAll(){
		Map<String, Object> useParams = new HashMap<String, Object>();
		useParams.put("customer_id", UserBis.currUser());
		useParams.put("currPage", params.get("currPage"));
		useParams.put("pageSize", params.get("pageSize"));
		useParams.put("real_name", params.get("real_name"));
		useParams.put("user_name", params.get("user_name"));
		useParams.put("isPage", Constants.DATAISPAGE_YES);
		Object[] arguments = new Object[]{useParams};
		String res = HproseClinetService.synCall(APIConstants.OMSI_GETOPERATOR, arguments,APIConstants.CUSTOMER_HOST, APIConstants.CUSTOMER_PORT);
		JSONObject json  = JSONObject.parseObject(res);
		renderJSON(json);
	}
	public static void addOperator(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("customer_id", UserBis.currUser());
		map.put("real_name", params.get("real_name"));
		map.put("terminal_card_no", params.get("terminal_card_no"));
		map.put("terminal_user_name", params.get("terminal_user_name"));
		map.put("operator_mac", params.get("operator_mac"));
		map.put("is_active", "1");
		map.put("role", params.get("role"));
		Object[] arguments = new Object[]{map};
		LogsUtils.addLogs(Constants.LOG_TYPE_ADD,Convert.convertToInt(UserBis.currOperatorId(),-1), 1, "添加操作员执行","success", UserBis.currLoginAccount(), UserBis.currUserName(), UserBis.currUser());
		String res = HproseClinetService.synCall(APIConstants.OMSI_ADDOPERATOR, arguments,APIConstants.CUSTOMER_HOST, APIConstants.CUSTOMER_PORT);
		JSONObject json = JSONObject.parseObject(res);
		renderJSON(json);
	}
	public static void delOperator(String operator_id){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("customer_id", UserBis.currUser());
		map.put("operator_id",operator_id);
		Object[] arguments = new Object[]{map};
		LogsUtils.addLogs(Constants.LOG_TYPE_DEL,Convert.convertToInt(UserBis.currOperatorId(),-1), 1, "删除操作员执行","success", UserBis.currLoginAccount(), UserBis.currUserName(), UserBis.currUser());
		String res = HproseClinetService.synCall(APIConstants.OMSI_DELETEOPERATOR, arguments,APIConstants.CUSTOMER_HOST, APIConstants.CUSTOMER_PORT);
		renderText(res);
	}
	
	public static void addOperatorMac(String operator_id,String operator_mac,String fingerprint){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("customer_id", UserBis.currUser());
		map.put("operator_id", operator_id);
		map.put("operator_mac", operator_mac);
		map.put("fingerprint", fingerprint);
		Object[] arguments = new Object[]{map};
		LogsUtils.addLogs(Constants.LOG_TYPE_UPDATE,Convert.convertToInt(UserBis.currOperatorId(),-1), 1, "修改操作员MAC地址执行","success", UserBis.currLoginAccount(), UserBis.currUserName(), UserBis.currUser());
		String res = HproseClinetService.synCall(APIConstants.OMSI_ADDOPERATORMAC, arguments,APIConstants.CUSTOMER_HOST, APIConstants.CUSTOMER_PORT);
		JSONObject json = JSONObject.parseObject(res);
		renderJSON(json);
	}
}
